﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

/// <summary>
/// Summary description for GooglePoints
/// </summary>
public class Markers : CollectionBase
{
	public Markers()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public Markers Clone()
    {
        Markers p = new Markers();
        for (int i = 0; i < this.Count; i++)
        {
            p.Add(new Marker(this[i].ID, this[i].Position, this[i].IconImage, this[i].InfoWindow, this[i].ToolTip, this[i].Draggable));
        }
        return p;
    }


    public Marker this[int pIndex]
    {
        get
        {
            return (Marker)this.List[pIndex];
        }
        set
        {
            this.List[pIndex] = value;
        }
    }

    public Marker this[string pID]
    {
        get
        {
            for (int i = 0; i < Count; i++)
            {
                if (this[i].ID == pID)
                {
                    return (Marker)this.List[i];
                }
            }
            return null;
        }
        set
        {
            for (int i = 0; i < Count; i++)
            {
                if (this[i].ID == pID)
                {
                    this.List[i] = value;
                }
            }
        }
    }

    public void Add(Marker pPoint)
    {
        this.List.Add(pPoint);
    }
    public void Remove(int pIndex)
    {
        this.RemoveAt(pIndex);
    }
    public void Remove(string pID)
    {
        for (int i = 0; i < Count; i++)
        {
            if (this[i].ID == pID)
            {
                this.List.RemoveAt(i);
                return;
            }
        }
    }

    public override bool Equals(System.Object obj)
    {
        // If parameter is null return false.
        if (obj == null)
        {
            return false;
        }

        // If parameter cannot be cast to Point return false.
        Markers p = obj as Markers;
        if ((System.Object)p == null)
        {
            return false;
        }

        if (p.Count != Count)
            return false;


        for (int i = 0; i < p.Count; i++)
        {
            if (!this[i].Equals(p[i]))
                return false;
        }
        // Return true if the fields match:
        return true;
    }


}